#include "./../inc/main_page.h"

MainPage *MainPage::m_instance = NULL;

MainPage *MainPage::instance(GameManager *gameManager, Lcd *lcd)
{
    // 如果没有实例则创建实例
    if (m_instance == NULL)
    {
        m_instance = new MainPage(gameManager, lcd);
    }
    return m_instance;
}

void MainPage::delInstance()
{
    // 释放实例空间
    delete m_instance;
    m_instance = NULL;
}

bool MainPage::handleTouch(const Point &touch_point)
{
    if (touch_point.x() >= 320 && touch_point.x() <= 480 && touch_point.y() >= 320 && touch_point.y() <= 380)
    {
        continueGame();
        return true;
    }
    else if (touch_point.x() >= 320 && touch_point.x() <= 480 && touch_point.y() >= 400 && touch_point.y() <= 460)
    {
        startNewGame();
        return true;
    }
    else
    {
        return false;
    }
}

void MainPage::continueGame()
{
    gameManager->mainReloadGame();
}

void MainPage::startNewGame()
{
    gameManager->showLevelPopup();
}

// 显示页面实现
void MainPage::show()
{
    bg.show(lcd->addr(), 0, 0);
}

// 隐藏页面实现
void MainPage::hide() {}